﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ViewModel;
using MODEL;
using GalaSoft.MvvmLight.Messaging;
using System.Windows.Media.Animation;
using System.Reflection;
using GalaSoft.MvvmLight.Ioc;
using Common;
using System.Threading;

namespace msap
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Messenger.Default.Register<string>(this, "MainWindow_OpenSubMenu", msg => OpenSubMenu(msg));
            Messenger.Default.Register<string>(this, "MainWindow_CloseSubMenu", msg => CloseSubMenu(msg));
        }

        private void OpenSubMenu(string message)
        {
            Storyboard openSubMenuStoryboard = this.FindResource("OpenSubMenuAnimation") as Storyboard;
            this.BeginStoryboard(openSubMenuStoryboard);
        }

        private void CloseSubMenu(string message)
        {
            Storyboard closeSubMenuStoryboard = this.FindResource("CloseSubMenuAnimation") as Storyboard;
            this.BeginStoryboard(closeSubMenuStoryboard);
        }

        private void WorkingArea_Navigating(object sender, NavigatingCancelEventArgs e)
        {
            SimpleIoc.Default.GetInstance<IWaitingService>().StartWaitingAsync("正在加载");
        }

        private void WorkingArea_Navigated(object sender, NavigationEventArgs e)
        {
            SimpleIoc.Default.GetInstance<IWaitingService>().StopWaitingAsync();
        }
    }
}
